package main

import "fmt"

type HeroNode struct {
	no       int
	name     string
	nickName string
	next     *HeroNode
}

func InsertHeroNode(head *HeroNode, newHeroNode *HeroNode) {
	temp := head
	for {
		if temp.next == nil {
			break
		}
		temp = temp.next
	}
	temp.next = newHeroNode

}
func InsertHeroNode2(head *HeroNode, newHeroNode *HeroNode) {
	temp := head
	flag := true
	for {
		if temp.next == nil {
			break
		} else if temp.next.no > newHeroNode.no {
			break
		} else if temp.next.no == newHeroNode.no {
			flag = false
			break
		}
		temp = temp.next
	}

	if !flag {
		fmt.Println("对不起，已经存在no=", newHeroNode.no)
		return
	} else {
		newHeroNode.next = temp.next
		temp.next = newHeroNode
	}

}
func LisrHeroNode(head *HeroNode) {
	temp := head.next
	if temp.next == nil {
		fmt.Println("空链表")
		return
	}
	for {
		fmt.Printf("[%d ,%s ,%s]==>", temp.no, temp.name, temp.nickName)
		temp = temp.next
		if temp == nil {
			break
		}
	}

}
func DeleteNode(head *HeroNode, id int) {
	temp := head
	flag := false
	for {
		if temp.next == nil {
			break
		} else if temp.next.no == id {
			break
		}
		temp = temp.next
	}
	if flag {
		temp.next = temp.next.next
	} else {
		fmt.Println("要删除的id不存在")
	}
}
func main() {
	head := &HeroNode{}
	her01 := &HeroNode{
		no:       1,
		name:     "宋江",
		nickName: "及时雨",
	}
	her02 := &HeroNode{
		no:       2,
		name:     "卢俊义",
		nickName: "玉麒麟",
	}
	InsertHeroNode(head, her01)
	InsertHeroNode(head, her02)
	LisrHeroNode(head)
}
